package com.titaniume.activitiweb;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.Model;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;

/**
 *@program: activiti7_workflow
 *@description: 流程部署
 *@author: renfei.huang
 *@create: 2021-11-09 11:33
 */
@SpringBootTest
public class Part1_Deployment {

    //act_re_deployment act_ge_bytearray
    @Autowired
    private RepositoryService repositoryService;

    //通过bpmn部署流程
    @Test
    public void initDeloymentBPMN() {

        String fileName = "bpmn/Part8_ProcessRuntime.bpmn";
        // String pngname="bpmn/Part1_Deployment.png";
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource(fileName)
                // .addClasspathResource(pngname) //图片
                .name("流程部署测试新特性PRuntime")
                .deploy();
        System.out.println(deployment.getName());

    }

    //通过zip部署流程
    @Test
    public void initDeploymentZIP() {

        InputStream fileInputStream = this.getClass()
                .getClassLoader()
                .getResourceAsStream("bpmn/Part1_Deployment - V2.zip");

        ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
        Deployment deployment = repositoryService.createDeployment()
                .addZipInputStream(zipInputStream)
                .name("流程部署测试zip")
                .deploy();

        System.out.println(deployment.getName());

    }


    //查询流程部署
    @Test
    public void getDeloyments() {

        List<Deployment> list = repositoryService.createDeploymentQuery().list();
        for (Deployment deployment : list) {
            System.out.println("ID:" + deployment.getId());
            System.out.println("NAME:" + deployment.getName());
            System.out.println("DeploymentTime:" + deployment.getDeploymentTime());
            System.out.println("key:" + deployment.getKey());
        }
    }
}
